<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改轮播图')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-pic-edit" th:object="${recipeSlidePic}">
            <input name="picId" th:field="*{picId}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">图片：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="hidden" name="picUrl" id="pic" th:field="*{picUrl}">
                    <a id="url"><img style="width: 90px;height: 90px" th:src="*{picUrl}"></a>
                    <input type="file" id="picUrl">
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">食谱ID：</label>
                    <div class="col-sm-8">
                        <input name="dishId" th:field="*{dishId}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">跳转URL：</label>
                    <div class="col-sm-8">
                        <input name="jumpUrl" th:field="*{jumpUrl}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">备注：</label>
                    <div class="col-sm-8">
                        <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "recipe/pic";
        $("#form-pic-edit").validate({
            focusCleanup: true
        });

        // 上传文件
        $("#picUrl").change(function () {
            var data = new FormData();
            data.append("file", $("#picUrl")[0].files[0]);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    // alert(JSON.stringify(result))
                    if (result.code == web_status.SUCCESS) {
                        $("#url img").attr("src",result.fileName)
                        $("#pic").val(result.fileName)
                    }
                },
                error: function(error) {
                    alert("图片上传失败。");
                }
            });
        })

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-pic-edit').serialize());
            }
        }
    </script>
</body>
</html>